package com.example.book_manage_240827.model;

import com.example.book_manage_240827.enums.ResultStatus;
import lombok.Data;

@Data
public class Result {
    private ResultStatus status;
    private String errorMessage;
    private Object data;
    /**
     * 业务执⾏成功时返回的⽅法
     *
     * @param data
     * @return
     */
    public static Result success(Object data) {
        Result result = new Result();
        result.setStatus(ResultStatus.SUCCESS);
        result.setErrorMessage("");
        result.setData(data);
        return result;
    }
    /**
     * 业务执⾏失败时返回的⽅法
     *
     * @param
     * @return
     */
    public static Result fail(String msg) {
        Result result = new Result();
        result.setStatus(ResultStatus.FAIL);
        result.setErrorMessage(msg);
        result.setData("");
        return result;
    }
    /**
     * 业务执⾏失败时返回的⽅法
     *
     * @param
     * @return
     */
    public static Result unlogin() {
        Result result = new Result();
        result.setStatus(ResultStatus.UNLOGIN);
        result.setErrorMessage("⽤⼾未登录");
        result.setData(null);
        return result;
    }
}

